package com.bxait.toymail.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.bxait.com.utils.PageUtils;
import com.bxait.com.utils.R;
import com.bxait.com.vo.product.BrandVo;
import com.bxait.com.vo.product.CateLogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bxait.toymail.product.entity.CategoryBrandRelationEntity;
import com.bxait.toymail.product.service.CategoryBrandRelationService;



/**
 * import org.apache.shiro.authz.annotation.RequiresPermissions;
 * 品牌分类关联
 *
 * @author chen
 * @email 2277411582@qq.com
 * @date 2023-03-13 22:26:35
 */
@RestController
@RequestMapping("product/categorybrandrelation")
public class CategoryBrandRelationController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = categoryBrandRelationService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * @param brandId
     * @==============History===============<br/>
     * @Description // TODO  获取品牌关联的分类
     * @Date 2023/3/20 20:11
     * @Author <a href="qq:2277411582@qq.com">chen</a>
     * @return com.bxait.com.utils.R
     */
    @GetMapping("/cateLog/list")
    public R cateLogList(@RequestParam("brandId")Long brandId){
        List<CateLogVo> vos = categoryBrandRelationService.getCateLogByBrandId(brandId);
        return R.ok().put("data", vos);
    }

    /**
     * @param catId
     * @==============History===============<br/>
     * @Description // TODO  获取分类关联的品牌
     * @Date 2023/3/20 19:59 
     * @Author <a href="qq:2277411582@qq.com">chen</a>
     * @return com.bxait.com.utils.R
     */ 
    @GetMapping("/brands/list")
    public R relationBrandsList(@RequestParam(value = "catId",required = true)Long catId){
        List<BrandVo> vos = categoryBrandRelationService.getBrandsByCatId(catId);
        return R.ok().put("data", vos);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);

        return R.ok().put("categoryBrandRelation", categoryBrandRelation);
    }

    /**
     * @param categoryBrandRelation
     * @==============History===============<br/>
     * @Description // TODO  保存
     * @Date 2023/3/20 20:20
     * @Author <a href="qq:2277411582@qq.com">chen</a>
     * @return com.bxait.com.utils.R
     */
    @RequestMapping("/save")
    public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.saveDetail(categoryBrandRelation);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.updateById(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		categoryBrandRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
